﻿
@{
    ViewBag.Title = "VideoList";
    Layout = "~/Views/Shared/_BCLayout.cshtml";
}

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>视频列表</legend>
</fieldset>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">搜索</label>
        <div class="layui-input-block">
            <input type="text" id="SearchText" name="Title1" required lay-verify="required" onkeypress="getKey()" placeholder="标题关键字" class="layui-input" style="width:300px;float:left;">
            <input type="text" value="" style="display:none" />
            <button type="button" class="layui-btn layui-btn-normal" style="float:left;" onclick="SearchFunc()"><i class="layui-icon">&#xe615;</i></button>
        </div>
    </div>
</form>
<table id="demo" lay-filter="VideoList"></table>

<script type="text/javascript">
    var table;
    layui.use('table', function () {
        table = layui.table;
        var tab = parent.tab;
        //第一个实例
        table.render({
            elem: '#demo'
            , method: 'post'
            //, height: 315
            , url: '/Home/UploadTableRequest' //数据接口
            , page: true //开启分页
            , where: { SortName: "VideoId", Order: "Desc", Condition: " and 1=1" }
            , limits: [50, 100, 200]
            , limit:50
            , cols: [[ //表头
                { field: 'Title', title: '标题', width: 600 }
                //, { field: 'Title3', title: '标题3', width: 200 }
                , { field: 'UploadTime', title: '发表时间', width: 180 }
                , {
                    field: 'State', title: '转换状态', width: 120,
                    templet: function (d) {
                        if (d.State == 0) {
                            return '待转';
                        }
                        else if (d.State == 1) {
                            return "转换中";
                        }
                        else if (d.State == 2) {
                            return "完成转换"
                        }
                    }
                }
                , {
                    field: "operation", title: "操作", width: 200,
                    templet: function (d) {
                        if (d.State == 0) {
                            return '<a class="layui-btn layui-btn-xs" lay-event="Trans">转换</a>';
                        }
                        else {
                            return "";
                        }
                    }
                }
            ]]
        });

        table.on("tool(VideoList)", function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            //GetArticle
            if (layEvent == 'Trans') {
                //alert(data.ArticleId);
                $.ajax({
                    type: "POST",
                    url: "/Home/API_TransfromVideo",
                    async: false,
                    data: { "VideoId": data.VideoId, "VideoUrl": data.VideoUrl },
                    success: function (msg) {
                        if (msg.result == "OK") {
                            alert("已经开启转换");                           
                        } else {
                            alert("开启转换失败");
                        }
                    }
                });
            }
        });



    });

    function getKey() {
        if (event.keyCode == 13) {
            SearchFunc();
        }
    }


    function SearchFunc() {
        var text = $("#SearchText").val();
        if (text == "") {
            table.reload("demo", {
                where: { SortName: "VideoId", Order: "Desc", Condition: " and 1=1" }
                , page: {
                    curr: 1
                }
            });
        }
        else {
            table.reload("demo", {
                where: {
                    SortName: "VideoId", Order: "Desc", Condition: " and Title like '%" + text + "%'"
                }
                , page: {
                    curr: 1
                }
            });
        }
    }



</script>